package com.example.mobile2032021606127cxz0304;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
TextView tvResult;//定义1个文本控件变量
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
   tvResult=findViewById(R.id.tvResult);

   //计算从1+2+3+……+10的结果
int result;
result=0;
for(int i=0;i<10;i++){
    result+=i;
}
result=myAdd(result,10);
tvResult.setText("结果："+ String.valueOf(result));
    }
    private int myAdd(int result, int i) {
        return result+i;
    }
}